-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathScreen.vb
149 lines (138 loc) · 6.09 KB
/
Screen.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Namespace My
''' <summary>
''' 屏幕截图相关函数
''' </summary>
''' <remarks></remarks>
Partial Public NotInheritable Class Screen
''' <summary>
''' 获取屏幕截图(全屏区域的截图)
''' </summary>
''' <returns>结果图片(失败返回1*1个像素,#00000000透明色的图片)</returns>
''' <remarks></remarks>
Public Shared Function Image() As Bitmap
Try
Dim ScreenArea As Rectangle = My.Computer.Screen.Bounds
Dim Temp As New Bitmap(ScreenArea.Width, ScreenArea.Height)
Dim Graphics As Graphics = Graphics.FromImage(Temp)
Graphics.CopyFromScreen(0, 0, 0, 0, ScreenArea.Size)
Graphics.Dispose()
Return Temp
Catch ex As Exception
Return New Bitmap(1, 1)
End Try
End Function
''' <summary>
''' 获取屏幕截图(指定区域的截图)
''' </summary>
''' <param name="Area">指定区域(System.Drawing.Rectangle)</param>
''' <returns>结果图片(失败返回1*1个像素,#00000000透明色的图片)</returns>
''' <remarks></remarks>
Public Shared Function Image(ByVal Area As Rectangle) As Bitmap
Try
Dim Temp As New Bitmap(Area.Width, Area.Height)
Dim Graphics As Graphics = Graphics.FromImage(Temp)
Graphics.CopyFromScreen(Area.Left, Area.Top, 0, 0, Area.Size)
Graphics.Dispose()
Return Temp
Catch ex As Exception
Return New Bitmap(1, 1)
End Try
End Function
''' <summary>
''' 获取屏幕截图(全屏区域的缩略图)
''' </summary>
''' <param name="Scale">缩略比例(应大于0,且小于等于1)</param>
''' <returns>结果图片(失败返回1*1个像素,#00000000透明色的图片)</returns>
''' <remarks></remarks>
Public Shared Function ImageThumbnail(ByVal Scale As Double) As Bitmap
If Scale <= 0 Or Scale > 1 Then
Return New Bitmap(1, 1)
End If
Try
Dim Thumbnail As Bitmap
Dim ScreenArea As Rectangle = My.Computer.Screen.Bounds
Dim Temp As New Bitmap(ScreenArea.Width, ScreenArea.Height)
Dim Graphics As Graphics = Graphics.FromImage(Temp)
Graphics.CopyFromScreen(0, 0, 0, 0, ScreenArea.Size)
Graphics.Dispose()
Thumbnail = Temp.GetThumbnailImage(ScreenArea.Width * Scale, ScreenArea.Height * Scale, Nothing, New System.IntPtr(0))
Temp.Dispose()
Return Thumbnail
Catch ex As Exception
Return New Bitmap(1, 1)
End Try
End Function
''' <summary>
''' 获取屏幕截图(指定区域的缩略图)
''' </summary>
''' <param name="Area">指定区域(System.Drawing.Rectangle)</param>
''' <param name="Scale">缩略比例(应大于0,且小于等于1)</param>
''' <returns>结果图片(失败返回1*1个像素,#00000000透明色的图片)</returns>
''' <remarks></remarks>
Public Shared Function ImageThumbnail(ByVal Area As Rectangle, ByVal Scale As Double) As Bitmap
If Scale <= 0 Or Scale > 1 Then
Return New Bitmap(1, 1)
End If
Try
Dim Thumbnail As Bitmap
Dim Temp As New Bitmap(Area.Width, Area.Height)
Dim Graphics As Graphics = Graphics.FromImage(Temp)
Graphics.CopyFromScreen(Area.Left, Area.Top, 0, 0, Area.Size)
Graphics.Dispose()
Thumbnail = Temp.GetThumbnailImage(Area.Width * Scale, Area.Height * Scale, Nothing, New System.IntPtr(0))
Temp.Dispose()
Return Thumbnail
Catch ex As Exception
Return New Bitmap(1, 1)
End Try
End Function
''' <summary>
''' 获取屏幕区域
''' </summary>
''' <returns>结果区域值(System.Drawing.Rectangle)</returns>
''' <remarks></remarks>
Public Shared Function Area() As System.Drawing.Rectangle
Return My.Computer.Screen.Bounds
End Function
''' <summary>
''' 获取屏幕区域大小
''' </summary>
''' <returns>结果大小值(System.Drawing.Size)</returns>
''' <remarks></remarks>
Public Shared Function Size() As Size
Return My.Computer.Screen.Bounds.Size
End Function
''' <summary>
''' 获取屏幕中心点坐标
''' </summary>
''' <returns>结果坐标值(System.Drawing.Point)</returns>
''' <remarks></remarks>
Public Shared Function CenterPoint() As Point
Return New Point(My.Computer.Screen.Bounds.Width / 2, My.Computer.Screen.Bounds.Height / 2)
End Function
''' <summary>
''' 获取屏幕工作区域
''' </summary>
''' <returns>结果区域值(System.Drawing.Rectangle)</returns>
''' <remarks></remarks>
Public Shared Function WorkingArea() As System.Drawing.Rectangle
Return My.Computer.Screen.WorkingArea
End Function
''' <summary>
''' 获取屏幕工作区域大小
''' </summary>
''' <returns>结果大小值(System.Drawing.Size)</returns>
''' <remarks></remarks>
Public Shared Function WorkingAreaSize() As Size
Return My.Computer.Screen.WorkingArea.Size
End Function
''' <summary>
''' 获取屏幕工作区域中心点坐标
''' </summary>
''' <returns>结果坐标值(System.Drawing.Point)</returns>
''' <remarks></remarks>
Public Shared Function WorkingAreaCenterPoint() As Point
Return New Point(My.Computer.Screen.WorkingArea.Width / 2, My.Computer.Screen.WorkingArea.Height / 2)
End Function
End Class
End Namespace